<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="manageRawMaterials" binding="#{productManagerBean.loadManageRawMaterials}">
                    <p:panel header="Raw Materials" id="rawMaterialsPanel">
                        <p:messages />
                        
                        <p:dataTable id="rawMaterials" var="rawMaterial" value="#{productManagerBean.rawMaterials}" selectionMode="single" 
                                     selection="#{productManagerBean.selectedRawMaterial}" update="rawMaterialsPanel"  paginator="true" rows="10"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >
                            <p:column filterBy="#{rawMaterial.name}" headerText="Name" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.name}" />  
                            </p:column> 
                            <p:column filterBy="#{rawMaterial.description}" headerText="Description" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.description}" />  
                            </p:column> 
                            <p:column filterBy="#{rawMaterial.leadTime}" headerText="Lead Time (weeks)" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.leadTime}" />  
                            </p:column>
                            <p:column filterBy="#{rawMaterial.shelfLife}" headerText="Shelf Life (months)" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.shelfLife}" />  
                            </p:column> 
                            <p:column filterBy="#{rawMaterial.lotSize}" headerText="Lot Size" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.lotSize}" />  
                            </p:column> 
                            <p:column filterBy="#{rawMaterial.status}" headerText="Status" filterMatchMode="contains">  
                                <h:outputText value="#{rawMaterial.status}" />  
                            </p:column> 
                        </p:dataTable>
                        <table class="table-submit">
                            <tr>
                                <td align="center">
                                    <p:commandButton id="btnAddARawMaterial" value="Add a Raw Material" 
                                                     title="Add a raw material." ajax="true"
                                                     actionListener="#{productManagerBean.addRawMaterial}" />
                                    &nbsp;&nbsp;&nbsp;
                                    <p:commandButton id="btnUpdateARawMaterial" value="Update Raw Material" 
                                                     title="Update selected raw material." ajax="true"
                                                     update="rawMaterialsPanel"
                                                     actionListener="#{productManagerBean.updateRawMaterial}" />
                                    &nbsp;&nbsp;&nbsp;
                                    <p:commandButton id="btnRemoveRawMaterial" value="Remove Raw Material" 
                                                     onclick="confirmation.show()" type="button"
                                                     title="Remove the selected raw material." />
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:confirmDialog  width="400" message="" header="Removing a raw material" severity="alert" widgetVar="confirmation">
                        <f:facet name="message">
                            <h:outputText value="You are going to remove a raw material."/><br/>
                            <h:outputText value="Are you sure you want to continue?"/>
                        </f:facet>    
                        <table width="100%">
                            <tr>
                                <td align="center">
                                    <p:commandButton value="Yes" update="rawMaterialsPanel" onclick="confirmation.hide()"
                                                     actionListener="#{productManagerBean.removeRawMaterial}"/>
                                    &nbsp;
                                    &nbsp;&nbsp;
                                    <p:commandButton value="No" update="rawMaterialsPanel" onclick="confirmation.hide()" type="button" />
                                </td>
                            </tr>
                        </table>

                    </p:confirmDialog>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
